package common.data.customerservice
{
	import common.model.WqClientInfo;
	import common.model.WqStaffInfo;
	
	import flash.utils.ByteArray;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;

	
	public class CustomerService extends RemoteObject
	{
		
		public var saveWqClientInfoHandle:Function;
		public var deleteWqClientInfoHandle:Function;
		public var findWqClientInfoHandle:Function;
		public var findMapRegoinByIdsHandle:Function;
		public var updateClientRegionHandle:Function;
		public var dealImportClientHandle:Function
		/********************************************************************************/
		public var saveWqVisitPlanHandle:Function;
		public var batchDeleteWqVisitPlanHandle:Function;
		public var findWqVisitPlanHandle:Function;
		public var findWqClientInfoByStaffHandle:Function;
		/********************************************************************************/
		public var saveWqTravelPlanHandle:Function;
		public var batchDeleteWqTravelPlanHandle:Function;
		public var findWqTravelPlanHandle:Function;
		
		public var failHandle:Function;
		
		public function CustomerService()
		{
			super("customerService");
			this.showBusyCursor = true;
			
			this.getOperation("saveWqClientInfo").addEventListener(ResultEvent.RESULT,saveWqClientInfoResult,false,0,true);
			this.getOperation("saveWqClientInfo").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("deleteWqClientInfo").addEventListener(ResultEvent.RESULT,deleteWqClientInfoResult,false,0,true);
			this.getOperation("deleteWqClientInfo").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("findWqClientInfo").addEventListener(ResultEvent.RESULT,findWqClientInfoResult,false,0,true);
			this.getOperation("findWqClientInfo").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("findMapRegoinByIds").addEventListener(ResultEvent.RESULT,findMapRegoinByIdsResult,false,0,true);
			this.getOperation("findMapRegoinByIds").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("updateClientRegion").addEventListener(ResultEvent.RESULT,updateClientRegionResult,false,0,true);
			this.getOperation("updateClientRegion").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			/********************************************************************************/

			this.getOperation("saveWqVisitPlan").addEventListener(ResultEvent.RESULT,saveWqVisitPlanResult,false,0,true);
			this.getOperation("saveWqVisitPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("batchDeleteWqVisitPlan").addEventListener(ResultEvent.RESULT,batchDeleteWqVisitPlanResult,false,0,true);
			this.getOperation("batchDeleteWqVisitPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("findWqVisitPlan").addEventListener(ResultEvent.RESULT,findWqVisitPlanResult,false,0,true);
			this.getOperation("findWqVisitPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("findWqClientInfoByStaff").addEventListener(ResultEvent.RESULT,findWqClientInfoByStaffResult,false,0,true);
			this.getOperation("findWqClientInfoByStaff").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			/********************************************************************************/
			
			this.getOperation("saveWqTravelPlan").addEventListener(ResultEvent.RESULT,saveWqTravelPlanResult,false,0,true);
			this.getOperation("saveWqTravelPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("batchDeleteWqTravelPlan").addEventListener(ResultEvent.RESULT,batchDeleteWqTravelPlanResult,false,0,true);
			this.getOperation("batchDeleteWqTravelPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);

			this.getOperation("findWqTravelPlan").addEventListener(ResultEvent.RESULT,findWqTravelPlanResult,false,0,true);
			this.getOperation("findWqTravelPlan").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
			this.getOperation("dealImportClient").addEventListener(ResultEvent.RESULT,dealImportClientResult,false,0,true);
			this.getOperation("dealImportClient").addEventListener(FaultEvent.FAULT,failCallBack,false,0,true);
			
		}
		
		/********************************************************************************/
		//保存操作
		public function saveWqClientInfo(entity:WqClientInfo):void{
			this.getOperation("saveWqClientInfo").send(entity);
		}
		//删除操作
		public function deleteWqClientInfo(entity:WqClientInfo):void{
			this.getOperation("deleteWqClientInfo").send(entity);
		}
		//查询操作
		public function findWqClientInfo():void{
			this.getOperation("findWqClientInfo").send();
		}
		//查询操作
		public function updateClientRegion(entity:WqClientInfo,regions:ArrayCollection):void{
			this.getOperation("updateClientRegion").send(entity,regions);
		}
		//导入操作
		public function dealImportClient(btyes:ByteArray,parent:WqClientInfo):void{
			this.getOperation("dealImportClient").send(btyes,parent);
		}
		
		//保存回调
		private function saveWqClientInfoResult(e:ResultEvent):void{
			try{
				if(saveWqClientInfoHandle!=null){
					saveWqClientInfoHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//删除回调
		private function deleteWqClientInfoResult(e:ResultEvent):void{
			try{
				if(deleteWqClientInfoHandle!=null){
					deleteWqClientInfoHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//查询回调
		private function findWqClientInfoResult(e:ResultEvent):void{
			try{
				if(findWqClientInfoHandle!=null){
					findWqClientInfoHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}

		//查询回调
		private function findMapRegoinByIdsResult(e:ResultEvent):void{
			try{
				if(findMapRegoinByIdsHandle!=null){
					findMapRegoinByIdsHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		//查询回调
		private function updateClientRegionResult(e:ResultEvent):void{
			try{
				if(updateClientRegionHandle!=null){
					updateClientRegionHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		//导入回调
		private function dealImportClientResult(e:ResultEvent):void{
			try{
				if(dealImportClientHandle!=null){
					dealImportClientHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		/********************************************************************************/
		//保存拜访计划
		public function saveWqVisitPlan(entity:ArrayCollection):void{
			this.getOperation("saveWqVisitPlan").send(entity);
		}
		//删除拜访计划
		public function batchDeleteWqVisitPlan(array:ArrayCollection):void{
			this.getOperation("batchDeleteWqVisitPlan").send(array);
		}
		//查询拜访计划
		public function findWqVisitPlan(startDate:String,endDate:String,selectedNode:Object):void{
			this.getOperation("findWqVisitPlan").send(startDate,endDate,selectedNode);
		}
		//查询拜访计划
		public function findWqClientInfoByStaff(staff:WqStaffInfo):void{
			this.getOperation("findWqClientInfoByStaff").send(staff);
		}
		
		//保存回调
		private function saveWqVisitPlanResult(e:ResultEvent):void{
			try{
				if(saveWqVisitPlanHandle!=null){
					saveWqVisitPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//删除回调
		private function batchDeleteWqVisitPlanResult(e:ResultEvent):void{
			try{
				if(batchDeleteWqVisitPlanHandle!=null){
					batchDeleteWqVisitPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//查询回调
		private function findWqVisitPlanResult(e:ResultEvent):void{
			try{
				if(findWqVisitPlanHandle!=null){
					findWqVisitPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		//查询回调
		private function findWqClientInfoByStaffResult(e:ResultEvent):void{
			try{
				if(findWqClientInfoByStaffHandle!=null){
					findWqClientInfoByStaffHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		/********************************************************************************/
		//保存差旅计划
		public function saveWqTravelPlan(entity:ArrayCollection):void{
			this.getOperation("saveWqTravelPlan").send(entity);
		}
		//删除差旅计划
		public function batchDeleteWqTravelPlan(array:ArrayCollection):void{
			this.getOperation("batchDeleteWqTravelPlan").send(array);
		}
		//查询差旅计划
		public function findWqTravelPlan(travelReason:String,startDate:String,endDate:String,staffIds:Array):void{
			this.getOperation("findWqTravelPlan").send(travelReason,startDate,endDate,staffIds);
		}
		
		//保存回调
		private function saveWqTravelPlanResult(e:ResultEvent):void{
			try{
				if(saveWqTravelPlanHandle!=null){
					saveWqTravelPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//删除回调
		private function batchDeleteWqTravelPlanResult(e:ResultEvent):void{
			try{
				if(batchDeleteWqTravelPlanHandle!=null){
					batchDeleteWqTravelPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		//查询回调
		private function findWqTravelPlanResult(e:ResultEvent):void{
			try{
				if(findWqTravelPlanHandle!=null){
					findWqTravelPlanHandle.call(this,e);
				}
			}catch(error:Error){
				trace(error.getStackTrace());
			}
		}
		
		/************************************************************************************/
		//错误回调
		private function failCallBack(e:FaultEvent):void{
//			if(failCallBack){
//				failCallBack.apply();
//			}
		}
	}
}	